﻿using System;
using System.Collections.Generic;
using System.Xml.Linq;

namespace Common.Helper
{
    public static class XElementExtensions
    {
        public static bool IsNullOrEmpty(this XElement el)
        {
            return el == null || el.Value == String.Empty || el.Value.Equals("null", StringComparison.InvariantCultureIgnoreCase) 
                || el.Value.Equals("Unknown Currency", StringComparison.InvariantCultureIgnoreCase); // base handling of empty row for currency
        }

        public static XElement Element(this XElement el, Constants.XmlConstants constant)
        {
            return el.Element(constant.ToString());
        }

        public static IEnumerable<XElement> Descendants(this XElement el, Constants.XmlConstants constant)
        {
            return el.Descendants(constant.ToString());
        }
        public static IEnumerable<XElement> Ancestors(this XElement el, Constants.XmlConstants constant)
        {
            return el.Ancestors(constant.ToString());
        }
    }
}
